package com.tjs.lucky.Controller;

import com.tjs.lucky.common.Result;
import com.tjs.lucky.interfaces.facade.LotteryActivityBooth;
import com.tjs.lucky.rpc.entity.ActivityConfig;
import com.tjs.lucky.rpc.req.DrawReq;
import com.tjs.lucky.rpc.res.DrawRes;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;

/**
 * @author TJS
 * @Description
 * @create 2023/7/20 0:38
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private LotteryActivityBooth lotteryActivityBooth;


    @PostMapping("/createJob")
    public Result create(@RequestBody ActivityConfig activityConfig) {
        try {
            System.out.println(activityConfig);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            activityConfig.setActivityId(activityConfig.getActivityId());
            activityConfig.setActivityDesc("号外！号外!~~");
            activityConfig.setActivityName("你是那个幸运者吗？(" + activityConfig.getActivityId() + ")");
            activityConfig.setStrategyId(10002L);
            activityConfig.setCreator("tianjiashu");
            activityConfig.setStockCount(10000);
            activityConfig.setTakeCount(10);
            activityConfig.setBeginDateTime(activityConfig.getBeginDateTime());
            activityConfig.setEndDateTime(activityConfig.getEndDateTime());
//            activityConfig.setBeginDateTime(sdf.parse("2023-07-20 02:25:00"));
//            activityConfig.setEndDateTime(sdf.parse("2023-08-30 00:00:00"));
            lotteryActivityBooth.createActivity(activityConfig);
        } catch (Exception e) {
            return Result.buildErrorResult(e.getMessage());
        }
        return Result.buildSuccessResult();
    }

    @GetMapping("doOpen")
    /**
     * localhost:9090/test/doOpen?uId=tianjiashu&activityId=100002
     */
    private DrawRes doOpenAward(String uId, Long activityId) {
        return lotteryActivityBooth.doOpenAward(uId, activityId);
    }

    @PostMapping("doDraw")
    private Result doDraw(String uId, Long activityId) {
        return lotteryActivityBooth.doDraw(new DrawReq(uId,activityId,null,null));
    }
}
